import React, { Component } from 'react'
import { Route } from 'react-router-dom'
import nprogress from 'nprogress'
import 'nprogress/nprogress.css'
import { connect } from 'react-redux'

class ProgressRouter extends Component {

  render () {
    if (this.props.headerProgress) {
      nprogress.start()
    }
    return (
        <Route {...this.props} />
    )
  }
  // 组件生命周期
  componentDidMount() {
    if (this.props.headerProgress) {
      nprogress.done()
    }
  }
  componentDidUpdate() {
    if (this.props.headerProgress) {
      nprogress.done()
    }
  }
}

const mapStateToProps = (state) => ({
  headerProgress: state.headerProgress
})

export default connect(mapStateToProps, () => ({}))(ProgressRouter)